package com.example.text.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.text.entity.Result;
import com.example.text.entity.User;
import com.example.text.entity.Ware;
import com.example.text.service.WareService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;



@RestController
@RequestMapping("/api/ware")
public class WareController {

    @Autowired
    private WareService wareService;

    //新增
    @PostMapping("/add")
    public Result add(@RequestBody Ware ware){
        wareService.insertWare(ware);
        return Result.success();
    }

    //修改
    @PostMapping("/update")
    public Result update(@RequestBody Ware ware){
        wareService.updateWare(ware);
        return Result.success();
    }

    //逻辑删除
    @PostMapping("/delete/{WareId}")
    public Result delete(@PathVariable Integer WareId){
        wareService.deleteWare(WareId);
        return Result.success();
    }

    //查询全部
    @GetMapping("/selectAllWare")
    public Result selectAll() {
        List<Ware> wareList =wareService.selectAllWare();
        return Result.success(wareList);

    }
    //根据id查询
    @GetMapping("/selectWareById/{WareId}")
    public Result selectWareById(@PathVariable Integer WareId) {
        Ware ware =wareService.selectWareById(WareId);
        return Result.success(ware);

    }
    //根据name查询

    @GetMapping("/selectWareByName/{WareName}")
    public Result selectWareByName(@PathVariable String WareName) {
        List<Ware> wareList =wareService.selectWareByName(WareName);
        return Result.success(wareList);

    }







}